1   /*
2    * Copyright (C) 2013 The Guava Authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  
15  package com.google.common.collect.testing.google;
16  
17  import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER;
18  import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ITERATOR_REMOVE;
19  import static com.google.common.collect.testing.features.CollectionSize.ONE;
20  import static com.google.common.truth.Truth.assertThat;
21  
22  import com.google.common.annotations.GwtCompatible;
23  import com.google.common.collect.Lists;
24  import com.google.common.collect.Multimap;
25  import com.google.common.collect.testing.features.CollectionFeature;
26  import com.google.common.collect.testing.features.CollectionSize;
27  
28  import java.util.Iterator;
29  import java.util.List;
30  import java.util.Map;
31  
32  /**
33   * Tester for {@code Multimap.values}.
34   *
35   * @author Louis Wasserman
36   */
37  @GwtCompatible
38  public class MultimapValuesTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
39    public void testValues() {
40      List<V> expected = Lists.newArrayList();
41      for (Map.Entry<K, V> entry : getSampleElements()) {
42        expected.add(entry.getValue());
43      }
44      assertThat(multimap().values()).has().exactlyAs(expected);
45    }
46    
47    @CollectionFeature.Require(KNOWN_ORDER)
48    public void testValuesInOrder() {
49      List<V> expected = Lists.newArrayList();
50      for (Map.Entry<K, V> entry : getOrderedElements()) {
51        expected.add(entry.getValue());
52      }
53      assertThat(multimap().values()).has().exactlyAs(expected).inOrder();
54    }
55    
56    
57    @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
58    @CollectionSize.Require(ONE)
59    public void testValuesIteratorRemove() {
60      Iterator<V> valuesItr = multimap().values().iterator();
61      valuesItr.next();
62      valuesItr.remove();
63      assertTrue(multimap().isEmpty());
64    }
65  }